/*
 * seqFeederList.cpp
 *
 *  Created on: 2011-09-05
 *      Author: pawel
 */

#include"seqFeederList.h"
#include <stdexcept>
#include<Bpp/Seq/Sequence.h>
seqFeederList::seqFeederList()
:seqFeeder(),listSize(0)
{
	empty = seqList.empty();
	listSize = seqList.max_size();
}
seqFeederList::seqFeederList(size_t limit)
:seqFeeder(),listSize(limit)
{
	empty = seqList.empty();
}
seqFeederList::~seqFeederList(){
	for(std::list<bpp::BasicSequence*>::iterator it= seqList.begin();it != seqList.end();++it){
	//for(__gnu_cxx::slist<bpp::BasicSequence*>::iterator it= seqList.begin();it != seqList.end();++it){
		delete *it;
	}
}

bpp::BasicSequence* seqFeederList::getSeq(){
	if(empty)throw std::logic_error("List is Empty");
	bpp::BasicSequence *retPtr;
	retPtr = seqList.front();
	seqList.pop_front();
	empty = seqList.empty();

	if(productionEnded && empty){
		closed =true;

	}
	full = false;
	return retPtr;

}
void seqFeederList::pushSeq(bpp::BasicSequence* bs){
	if(full)return;
	//seqList.push_front(bs);
	seqList.push_back(bs);
	full = (seqList.size()>=listSize);
	empty = false;

}

void seqFeederList::pushAddParams(seqAlignParams *params, std::string seqName)
{
	optionalParams.insert(std::pair<std::string,seqAlignParams>(seqName,*params));
}



seqAlignParams *seqFeederList::getAddParam(std::string seqName)
{
	boost::unordered_map<std::string, seqAlignParams>::iterator iter;
		iter =optionalParams.find(seqName);
		if(iter == optionalParams.end()){
			return NULL;
		}
		seqAlignParams *retptr;
		retptr = new seqAlignParams(iter->second);
		optionalParams.erase(iter);
		return retptr;
}


